const mongoose = require('mongoose');

// 攻略模型
const StrategySchema = new mongoose.Schema({
  title: { type: String, required: true },
  description: { type: String, required: true },
  content: { type: String, required: true },
  destination: { type: String, required: true },
  author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
  images: [String],
  tags: [String],
  views: { type: Number, default: 0 },
  likes: { type: Number, default: 0 },
  difficulty: { type: String, enum: ['简单', '中等', '困难'], default: '中等' },
  duration: String, // 如：3天2夜
  budget: { type: Number }, // 预算
  season: [String], // 适合季节
  createdAt: { type: Date, default: Date.now },
  updatedAt: { type: Date, default: Date.now }
});

// 当地游模型
const LocalTourSchema = new mongoose.Schema({
  title: { type: String, required: true },
  description: { type: String, required: true },
  destination: { type: String, required: true },
  price: { type: Number, required: true },
  originalPrice: { type: Number },
  images: [String],
  duration: String, // 如：半日游、一日游
  groupSize: { type: Number, default: 1 }, // 团队人数
  includeServices: [String], // 包含服务
  highlights: [String], // 亮点
  rating: { type: Number, default: 5.0 },
  reviewCount: { type: Number, default: 0 },
  bookingCount: { type: Number, default: 0 },
  availableDates: [Date],
  provider: { type: String, required: true }, // 服务商
  isPopular: { type: Boolean, default: false },
  createdAt: { type: Date, default: Date.now }
});

// 自由行套餐模型
const FreeTourSchema = new mongoose.Schema({
  title: { type: String, required: true },
  description: { type: String, required: true },
  destination: { type: String, required: true },
  price: { type: Number, required: true },
  originalPrice: { type: Number },
  images: [String],
  duration: String, // 如：5天4夜
  flightIncluded: { type: Boolean, default: true },
  hotelIncluded: { type: Boolean, default: true },
  hotelLevel: { type: String, enum: ['经济型', '舒适型', '豪华型'], default: '舒适型' },
  flightType: { type: String, enum: ['经济舱', '商务舱', '头等舱'], default: '经济舱' },
  highlights: [String],
  itinerary: [{ 
    day: Number, 
    title: String, 
    activities: [String] 
  }],
  rating: { type: Number, default: 5.0 },
  reviewCount: { type: Number, default: 0 },
  bookingCount: { type: Number, default: 0 },
  isPopular: { type: Boolean, default: false },
  createdAt: { type: Date, default: Date.now }
});

// 跟团游模型
const GroupTourSchema = new mongoose.Schema({
  title: { type: String, required: true },
  description: { type: String, required: true },
  destination: { type: String, required: true },
  price: { type: Number, required: true },
  originalPrice: { type: Number },
  images: [String],
  duration: String,
  groupSize: { type: Number, required: true }, // 团队人数限制
  minGroupSize: { type: Number, default: 1 },
  includeServices: [String], // 包含服务：门票、酒店、餐食等
  excludeServices: [String], // 不含服务
  tourGuide: { type: Boolean, default: true }, // 是否含导游
  tourGuideLanguage: [String], // 导游语言
  itinerary: [{ 
    day: Number, 
    title: String, 
    activities: [String],
    meals: [String], // 早餐、午餐、晚餐
    accommodation: String 
  }],
  departureCity: String, // 出发城市
  departureDates: [Date], // 出发日期
  rating: { type: Number, default: 5.0 },
  reviewCount: { type: Number, default: 0 },
  bookingCount: { type: Number, default: 0 },
  tourOperator: { type: String, required: true }, // 旅行社
  isPopular: { type: Boolean, default: false },
  createdAt: { type: Date, default: Date.now }
});

// 酒店模型
const HotelSchema = new mongoose.Schema({
  name: { type: String, required: true },
  description: { type: String, required: true },
  destination: { type: String, required: true },
  address: { type: String, required: true },
  location: {
    latitude: Number,
    longitude: Number,
    city: String,
    country: String
  },
  images: [String],
  starRating: { type: Number, min: 1, max: 5 }, // 星级
  rating: { type: Number, default: 4.5 },
  reviewCount: { type: Number, default: 0 },
  priceRange: {
    min: Number,
    max: Number,
    currency: { type: String, default: 'CNY' }
  },
  roomTypes: [{
    type: String, // 标准间、豪华间、套房等
    price: Number,
    maxGuests: Number,
    amenities: [String] // 房间设施
  }],
  hotelAmenities: [String], // 酒店设施：游泳池、健身房、WiFi等
  policies: {
    checkIn: String, // 入住时间
    checkOut: String, // 退房时间
    cancellation: String, // 取消政策
    pets: Boolean // 是否允许宠物
  },
  contact: {
    phone: String,
    email: String,
    website: String
  },
  isPopular: { type: Boolean, default: false },
  bookingCount: { type: Number, default: 0 },
  createdAt: { type: Date, default: Date.now }
});

// 签证服务模型
const VisaServiceSchema = new mongoose.Schema({
  country: { type: String, required: true }, // 目标国家
  visaType: { type: String, required: true }, // 签证类型：旅游、商务、探亲等
  title: { type: String, required: true },
  description: { type: String, required: true },
  price: { type: Number, required: true }, // 服务费
  processingTime: { type: String, required: true }, // 处理时长
  validityPeriod: String, // 签证有效期
  stayDuration: String, // 停留时间
  entryTimes: String, // 入境次数：单次、多次
  requiredDocuments: [String], // 所需材料
  serviceIncludes: [String], // 服务包含
  successRate: { type: Number, default: 95 }, // 出签率
  urgentService: { type: Boolean, default: false }, // 是否提供加急服务
  urgentPrice: Number, // 加急费用
  urgentTime: String, // 加急处理时长
  provider: { type: String, required: true }, // 服务商
  rating: { type: Number, default: 4.8 },
  reviewCount: { type: Number, default: 0 },
  orderCount: { type: Number, default: 0 },
  isPopular: { type: Boolean, default: false },
  createdAt: { type: Date, default: Date.now }
});

// 导出模型
const Strategy = mongoose.model('Strategy', StrategySchema);
const LocalTour = mongoose.model('LocalTour', LocalTourSchema);
const FreeTour = mongoose.model('FreeTour', FreeTourSchema);
const GroupTour = mongoose.model('GroupTour', GroupTourSchema);
const Hotel = mongoose.model('Hotel', HotelSchema);
const VisaService = mongoose.model('VisaService', VisaServiceSchema);

module.exports = {
  Strategy,
  LocalTour,
  FreeTour,
  GroupTour,
  Hotel,
  VisaService
}; 